$(document).ready(function() {
	$(".search-query").keyup(function(e) {
		if (e.which == 13)
			initQuickSearch($(this).val());
	});
	$(".search-query").focus(function() {
		$(this).select();
	});

	loadLists();

	loadSideBarContents();

});
function initQuickSearch(value) {
	alert(value);
}

function loadLists() {
	$("select[url]").each(
			function(idx, obj) {
				$.getJSON($(obj).attr("url"), function(data) {
					$.each(data, function(idx, ele) {
						$(obj).append(
								"<option value='" + ele.value + "'>" + ele.text
										+ "</option>");
					});
				});
			});
}
function loadSideBarContents() {
	var a = function(url, selector) {
		$
				.getJSON(
						url,
						function(data) {
							var lines = "";
							$
									.each(
											data,
											function(idx, ele) {
												lines += "<li class='list-group-item'><a href='loadObject?type=" + ele.type;
												
												if(ele.hasOwnProperty('id'))
													lines+=+ "&id="	+ ele.id ;
												if(ele.hasOwnProperty('title'))
													lines += "' title='" + ele.title + "'";													
												
												lines += "><i class='fa "
														+ ele.iconClass
														+ "'></i><span>"
														+ ele.text
														+ "</span></a></li>";
											});
							
							$(selector).html(lines);
						});
	};

	a('loadBookmarks.htm?topOnly=true', "#bookmarks ul");
	a('loadReports.htm?topOnly=true', "#reports ul");
	a('loadProjectNavigator.htm?topOnly=true', "#navigator ul");

}
